TITLE seagullbird_t19
.MODEL SMALL
.DATA
	INPUT_INFO DB 'PLEASE ENTER A STRING ENDING WITH A DOLLAR SYMBOL (ENTER # TO QUIT):', 0AH, 0DH, '$'
	BUFF DB 80, ?, 80 DUP (?)
	WRONG_MSG DB 'PLEASE END YOUR STRING WITH A DOLLAR SYMBOL!', 0AH, 0DH, '$'
.CODE
MAIN PROC FAR
	ASSUME CS:_TEXT, DS:_DATA
	PUSH DS
	XOR AX, AX
	PUSH AX
	MOV AX, @DATA
	MOV DS, AX

	INPUT:
		MOV AH, 09H						; INPUT INFO
		LEA DX, INPUT_INFO
		INT 21H
		LEA DX, BUFF
		MOV AH, 0AH
		INT 21H

	MOV BX, 2
	ADD BX, DX
	CMP BYTE PTR [BX], 23H					; # TO QUIT
	JE FINAL

	XOR CL, CL 						; SAVE COUNTING RESULT

	FOR:
		CMP BYTE PTR [BX], 24H				; $ TO END STRING
		JE OUTPUT
		CMP BYTE PTR [BX], 0DH
		JE WRONG

		CMP BYTE PTR [BX], 30H				; <0	
		JL PLUS
		CMP BYTE PTR [BX], 39H				; >9
		JG PLUS

		NEXT:
			INC BX
			JMP FOR

		PLUS:
			INC CL
			JMP NEXT

	OUTPUT:
		MOV AH, 02H
		MOV DL, 0DH
		INT 21H
		MOV DL, 0AH
		INT 21H

		XOR AX, AX
		MOV AL, CL					; SAVE RESULT TO AX
		MOV CL, 10
		DIV CL
		MOV CH, AH 					; REMAINDER
		MOV CL, AL					; QUOTIENT
					
		CMP CL, 0					; QUOTIENT IS 0
		JZ REMAINDER
		MOV DL, 30H
		ADD DL, CL
		MOV AH, 02H
		INT 21H

		REMAINDER:
		MOV DL, 30H	
		ADD DL, CH
		MOV AH, 02H
		INT 21H


		MOV DL, 0DH
		INT 21H
		MOV DL, 0AH
		INT 21H
		JMP INPUT

	WRONG:
		MOV AH, 09H
		LEA DX, WRONG_MSG
		INT 21H
		JMP INPUT

	FINAL:
		RET
MAIN ENDP
	END MAIN